package com.common.vo;


import java.io.Serializable;

import lombok.Data;

/**
 * 页面返回数据
 * @author yyq
 *
 */
@Data
public class Result<T> implements Serializable{

	private static final long serialVersionUID = 1L;
	
	/** 状态*/
	private Integer code;		 
	/** 提示*/
	private String msg;		 
	/** 返回的对象*/
	private T data;	 
	/** 成功是否*/
	private Boolean success;   
	/** 总数*/
	private Long count;  	 
	
	/**
	 * 成功码:200
	 */
	public static final int SUCCESS_STATE = 200;
	/**
	 * 成功码:0
	 */
	public static final int SUCCESS_CODE = 0;
	/**
	 * 失败码:400
	 */
	public static final int FAIL_STATE = 400;
	/**
	 * 未授权码:401
	 */
	public static final int NOT_LOGIN_STATE = 401;
	/**
	 * 异常码:500
	 */
	public static final int ERROR_STATE = 500;
	/**
	 * 失败码:1
	 */
	public static final int FAIL_CODE = 1;
	/**
	 * 成功提示
	 */
	public static final String SUCCESS_MSG = "操作成功";
	/**
	 * 失败提示
	 */
	public static final String FAIL_MSG = "操作失败";
	/**
	 * 异常提示
	 */
	public static final String ERROR_MSG = "操作异常";
	/**
	 * 删除成功提示
	 */
	public static final String DELETE_MSG = "删除成功";
	/**
	 * 删除失败提示
	 */
	public static final String DELETE_FAIL_MSG = "删除失败";
	/**
	 * 添加成功提示
	 */
	public static final String ADD_MSG = "添加成功";
	/**
	 * 添加失败提示
	 */
	public static final String ADD_FAIL_MSG = "添加失败";
	/**
	 * 修改成功提示
	 */
	public static final String UPDATE_MSG = "修改成功";
	/**
	 * 修改失败提示
	 */
	public static final String UPDATE_FAIL_MSG = "修改失败";
	/**
	 * 加载成功提示
	 */
	public static final String LOAD_MSG = "加载成功";
	/**
	 * 参数错误提示
	 */
	public static final String PARAMETER_ERROR_MSG = "参数错误";
	/**
	 * 未授权提示
	 */
	public static final String NOT_LOGIN_MSG = "未登录授权（Unauthorized）";

	public static final String NOT_ACTIVATION_MSG = "未激活授权（not active）";

	public static final String UPDATE_SUCCESS = "更新成功";

	public static final String UPDATE_FAIL = "更新失败";

	public static final String CODE_ERROR_MSG = "账号密钥错误";

	
	/**
	 * --------------------------------------------------------------------------------------------------
	 * 成功操作
	 * @return
	 */
	public static <T> Result<T> success() {
		Result<T> result = new Result<T>();
		result.setCode(Result.SUCCESS_STATE);
		result.setMsg(Result.SUCCESS_MSG);
		result.setSuccess(true);
		return result;
	}
	public static <T> Result<T> success(T data) {
		Result<T> result = new Result<T>();
		result.setCode(Result.SUCCESS_STATE);
		result.setMsg(Result.SUCCESS_MSG);
		result.setData(data);
		result.setSuccess(true);
		return result;
	}
	
	public static <T> Result<T> success(String msg) {
		Result<T> result = new Result<T>();
		result.setCode(Result.SUCCESS_STATE);
		result.setMsg(msg);
		result.setSuccess(true);
		return result;
	}
	
	public static <T> Result<T> success(T data, String msg) {
		Result<T> result = new Result<T>();
		result.setCode(Result.SUCCESS_STATE);
		result.setMsg(msg);
		result.setData(data);
		result.setSuccess(true);
		return result;
	}


	/**
	 * --------------------------------------------------------------------------------------------------
	 * 失败操作
	 * @return
	 */
	public static <T> Result<T> fail() {
		Result<T> result = new Result<T>();
		result.setCode(Result.FAIL_STATE);
		result.setMsg(Result.FAIL_MSG);
		result.setSuccess(false);
		return result;
	}
	public static <T> Result<T> fail(T data) {
		Result<T> result = new Result<T>();
		result.setCode(Result.FAIL_STATE);
		result.setMsg(Result.FAIL_MSG);
		result.setData(data);
		result.setSuccess(false);
		return result;
	}
	
	public static <T> Result<T> fail(String msg) {
		Result<T> result = new Result<T>();
		result.setCode(Result.FAIL_STATE);
		result.setMsg(msg);
		result.setSuccess(false);
		return result;
	}
	
	public static <T> Result<T> fail(T data, String msg) {
		Result<T> result = new Result<T>();
		result.setCode(Result.FAIL_STATE);
		result.setMsg(msg);
		result.setData(data);
		result.setSuccess(false);
		return result;
	}

	/**
	 * --------------------------------------------------------------------------------------------------
	 * 未激活
	 * @param <T>
	 * @return
	 */
	public static <T> Result<T> notActivation() {
		Result<T> result = new Result<T>();
		result.setCode(Result.NOT_LOGIN_STATE);
		result.setMsg(Result.NOT_ACTIVATION_MSG);
		result.setSuccess(false);
		return result;
	}

	/**
	 * --------------------------------------------------------------------------------------------------
	 * 未登录
	 * @param <T>
	 * @return
	 */
	public static <T> Result<T> notLogin() {
		Result<T> result = new Result<T>();
		result.setCode(Result.NOT_LOGIN_STATE);
		result.setMsg(Result.NOT_LOGIN_MSG);
		result.setSuccess(false);
		return result;
	}

	/**
	 * --------------------------------------------------------------------------------------------------
	 * 系统异常
	 * @param <T>
	 * @return
	 */
	public static <T> Result<T> error() {
		Result<T> result = new Result<T>();
		result.setCode(Result.ERROR_STATE);
		result.setMsg(Result.ERROR_MSG);
		result.setSuccess(false);
		return result;
	}

	public static <T> Result<T> error(String msg) {
		Result<T> result = new Result<T>();
		result.setCode(Result.ERROR_STATE);
		result.setMsg(msg);
		result.setSuccess(false);
		return result;
	}


	/**
	 * --------------------------------------------------------------------------------------------------
	 * 分页返回
	 * @param data
	 * @param count
	 * @param <T>
	 * @return
	 */
	public static <T> Result<T> page(T data, Long count) {
		Result<T> result = new Result<T>();
		result.setCode(Result.SUCCESS_CODE);
		result.setMsg(Result.SUCCESS_MSG);
		result.setData(data);
		result.setSuccess(true);
		result.setCount(count);
		return result;
	}


	/**
	 * --------------------------------------------------------------------------------------------------
	 * 自定义
	 * @param data
	 * @param code
	 * @param success
	 * @param msg
	 * @param <T>
	 * @return
	 */
	public static <T> Result<T> custom(T data, Integer code, Boolean success,String msg) {
		Result<T> result = new Result<T>();
		result.setCode(code);
		result.setMsg(msg);
		result.setData(data);
		result.setSuccess(success);
		return result;
	}



	
}
